package com.example.zhu.result;

import lombok.Data;

//用泛型格式，如果controller返回的是页面数据，则return R.success(page);如果返回的是成功消息，则return R.success("success");如果返回错误消息，return R.error("错误原因");
@Data
public class Result<T> {

    private Integer code; //编码：1成功，0和其它数字为失败

    private String msg; //信息

    private T data; //数据

    //静态类，controller返回时直接return R.success(T);
    public static <T> Result<T> success(T object) {
        Result<T> result = new Result<T>();
        result.data = object;
        result.code = 1;
        return result;
    }

    public static<T> Result<T> success(){
        Result<T> result = new Result<>();
        result.code = 1;
        return result;
    }

    public static <T> Result<T> error(String msg) {
        Result result = new Result();
        result.msg = msg;
        result.code = 0;
        return result;
    }
}